<?php

namespace Wechat\Controller;

class MagazineController extends CommonController {

    public function index() {
        $type = $_REQUEST["type"];
        $this->assign("type", $type);
        $this->display("index");
    }

    public function magazineList() {
        $type = I("post.type");
        $map = null;
        if(!isNullOrEmpty($type)){
            $map["mg.type"] = $type;
        }
        $list = D("Magazine")->alias("mg")
//            ->join("left join __PRODUCT__ p on p.product_id = pd.product_id")
            ->where($map)
            ->order("mg.magazine_id ASC")
//            ->field("pd.*")
            ->select();
        echo json_encode($list);

    }

    public function detail() {

        $id = $_REQUEST["id"];

        $magazine = D("Magazine")->queryById($id);
        if(isNullOrEmpty($magazine)) {
            $this->redirect(U("magazine/index"));
        }

        $this->assign("magazine", $magazine);
        $this->display("detail");
    }
}